from django.contrib.auth import get_user_model
from django.db import models

OAUser = get_user_model()


# Create your models here.
class AbsentStatusChoices(models.IntegerChoices):
    """审批状态"""
    AUDITING = 1
    PASS = 2
    REJECTED = 3


class AbsentType(models.Model):
    """考勤类别"""
    name = models.CharField(max_length=100)
    create_time = models.DateTimeField(auto_now_add=True)


class Absent(models.Model):
    # 标题
    title = models.CharField(max_length=200)
    # 内容
    request_content = models.TextField()
    # 类型
    absent_type = models.ForeignKey(AbsentType, on_delete=models.CASCADE, related_name='absents',
                                    related_query_name='absents')
    # 如果在一个模型中, 有多个字段对同一个模型引用了外键, 那么必须指定 relate_name 为不同的值
    # 发起人
    requester = models.ForeignKey(OAUser, on_delete=models.CASCADE, related_name='my_absents',
                                  related_query_name='my_absents')
    # 审核人
    responder = models.ForeignKey(OAUser, on_delete=models.CASCADE, related_name='sub_absents',
                                  related_query_name='sub_absents', null=True)
    # 状态
    status = models.IntegerField(choices=AbsentStatusChoices, default=AbsentStatusChoices.AUDITING)
    # 开始日期
    start_date = models.DateTimeField()
    # 结束日期
    end_date = models.DateTimeField()
    # 发起时间
    create_time = models.DateTimeField(auto_now_add=True)
    # 回复内容
    response_content = models.TextField(blank=True)

    class Meta:
        ordering = ('-create_time',)
